package com.ayoka.mvp;

import android.text.TextUtils;

import com.ayoka.base.BasePresenter;
import com.ayoka.base.IBaseView;
import com.ayoka.bean.UserInformation;
import com.tencent.TIMCallBack;
import com.tencent.TIMManager;
import com.tencent.TIMUser;

/**
 * Created by gabriel on 2017/3/5.
 */

public interface MainMVP {

    interface MainModel {
    }

    interface IMainView extends IBaseView {
    }

    class MainPresenter extends BasePresenter<IMainView> {
        /**
         * 登录imsdk
         *
         * @param callBack 登录后回调
         */
        public void loginTIM(TIMCallBack callBack) {
            if (UserInformation.getInstance() == null) return;
            String identify = UserInformation.getInstance().tim_identifier;//用户id
            String userSig = UserInformation.getInstance().tim_user_sig;//用户签名
            if (TextUtils.isEmpty(identify) || TextUtils.isEmpty(userSig)) return;
            TIMUser user = new TIMUser();
            user.setAccountType(String.valueOf(UserInformation.getInstance().tim_sdk_account_type));
            user.setAppIdAt3rd(String.valueOf(UserInformation.getInstance().tim_sdk_appid));
            user.setIdentifier(identify);
            //发起登录请求
            TIMManager.getInstance().login(
                    UserInformation.getInstance().tim_sdk_appid,
                    user,
                    userSig,//用户帐号签名，由私钥加密获得，具体请参考文档
                    callBack);
        }
    }
}
